package com.tssup.fesco.common.frame.common;


import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

@JsonNaming(PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy.class)
public class DefaultWebResult {

    private final static String SUCCESS_CODE = "0";
    private final static String SUCCESS_MSG = "success";

    private final static DefaultWebResult SUCCESS_WITH_NO_RESULT = new DefaultWebResult(SUCCESS_MSG, SUCCESS_CODE);

    private String code;
    private String msg;
    private Object data;

    public DefaultWebResult() {
    }

    public DefaultWebResult(Object data) {
        this.data = data;
    }

    public DefaultWebResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public DefaultWebResult(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 创建一个成功的返回, 但不需要返回空数据。
     *
     * @return
     */
    public static DefaultWebResult success() {
        return SUCCESS_WITH_NO_RESULT;
    }

    /**
     * 创建一个成功的返回, 并返回指定的数据。
     *
     * @return
     */
    public static DefaultWebResult success(Object data) {
        DefaultWebResult result = new DefaultWebResult(SUCCESS_CODE, SUCCESS_MSG);
        result.setData(data);
        return result;
    }

    /**
     * 创建一个失败的返回。
     *
     * @return
     */
    public static DefaultWebResult failure(String errCode, String errMsg) {
        return new DefaultWebResult(errMsg, errCode);
    }

    /**
     * 创建一个失败的返回, 同时返回数据。
     *
     * @return
     */
    public static DefaultWebResult failure(String errCode, String errMsg, Object object) {
        return new DefaultWebResult(errCode, errMsg, object);
    }

}
